package com.toune.villager.activity

import android.bluetooth.BluetoothDevice
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.toune.dltools.ui.DLBaseActivity
import com.toune.villager.R
import com.toune.villager.fragment.HomeFragment
import com.toune.villager.fragment.LifeFragment
import com.toune.villager.fragment.MessageFragment
import com.toune.villager.fragment.MineFragment
import com.toune.villager.model.MainModel
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : DLBaseActivity<MainModel>() {

    override val layout: Int
        get() = R.layout.activity_main
    override val titleStr: String?
        get() = ""

    val fragments =
        arrayListOf<Fragment>(HomeFragment(), MessageFragment(), LifeFragment(), MineFragment())

    override fun init(savedInstanceState: Bundle?) {
        val myViewPagerAdapter = MyViewPagerAdapter(supportFragmentManager)
        dlNoScrollViewPager.adapter = myViewPagerAdapter
        dlNoScrollViewPager.offscreenPageLimit = fragments.size
        bottomNavView.setOnNavigationItemSelectedListener {
            dlNoScrollViewPager.setCurrentItem(it.order, false)
            return@setOnNavigationItemSelectedListener true
        }
//        dlNoScrollViewPager.setPageTransformer(true)
    }

    override fun initEventAndData() {
    }

    inner class MyViewPagerAdapter(
        fm: FragmentManager
    ) :
        FragmentStatePagerAdapter(fm) {

        override fun getCount(): Int {
            return fragments.size
        }

        override fun getItem(position: Int): Fragment {
            return fragments[position]
        }

    }
}
